在https://github.com/fnagel/jquery-ui的选择菜单中,我已经为每个选项设置了标题,并将其显示为图标。除了文件名中包含空格的图标外,其他图标运行正常。如果文件名类似于African Union.png,则不会显示图标
jquery:
$('select.flags').selectmenu({
icons: [
{find: '.icon'}
],
bgImage: function() {
return 'url(' + $(this).attr("title") + ')';
}
});html:
<option value="African Union.png" class="icon" title="/img/icons/flags/African Union.png" >African Union</option>如果我不能让它在jQuery中工作-如何使用php转义空格?str_replace是唯一的选择吗?
发布于 2012-03-10 17:57:50
URLs in CSS可以不加引号,也可以用单引号或双引号引起来。如果未加引号,则需要转义某些字符:
对于未加引号的URI中出现的某些字符,如括号、空格字符、单引号(')和双引号("),必须使用反斜杠进行转义,以便生成的URI值是URI标记:'\(','\)‘。
所以:
'url(' + $(this).attr("title").replace(/(?=[()\s'"])/g, '\\') + ')'或者将URL放在引号中,最好用双引号作为plain single quotes are allowed in URLs。
'url("' + $(this).attr("title") + '")'发布于 2012-03-10 17:55:13
使用urlencode。首先,URL中不能有空格。
$filename = "African Union.png";
$url = urlencode($filename);
$html_safe_url = htmlspecialchars($url);
echo "<option value='$html_safe_url' class='icon' title='/img/icons/flags/$html_safe_url'>African Union</option>发布于 2012-03-10 17:55:03
试试这个
$("#text_box_id").change(function() {
var name = $(this).val();
var dname_without_space = $("#text_box_id").val().replace(/ /g, "");
var name_without_special_char = dname_without_space.replace(/[^a-zA-Z 0-9]+/g, "");
$(this).attr("value", name_without_special_char );
});它将删除空格和特殊字符。请看这篇文章
https://stackoverflow.com/questions/9645477
复制相似问题