jQuery val在Chrome中无法正常工作 [英] jQuery val not working properly in Chrome
问题描述
$('#selectable1 span')。live('mousedown',function (){
var ff = $(this).css(font-family);
$(#family).val(ff);
});
当一个span元素被点击(mousedown)时,一个输入(#family)获取它的字体系列值。
它适用于FireFox,但在Chrome中它仅适用于仅由一个字组成的字体系列。格鲁吉亚将工作,但时代新罗马不会。
您可以在这里看到代码:
这有什么问题?
Thanx
您可以稍微更改脚本以替换WebKit在字体名称包含空格时添加的引号,像这样:
$('#selectable1 span')。live('mousedown',function(){
var(ff)= $(this).css(font-family)。replace(/ \'/ g,);
$(#family).val(ff);
});
这里有一个正则表达式方法,它可以从样式
中提取字面值,这可能比任何事情都容易,但我不是RegEx大师,有人可以自由地改善这一点,并更新答案(我吮吸RegEx,对不起!)这适用于你所有的例子。
I have a simple jQuery function:
$('#selectable1 span').live('mousedown', function() {
var ff = $(this).css("font-family");
$("#family").val(ff);
});
When a span element is clicked (mousedown) an input (#family) gets its font family value. It works in FireFox but in Chrome it works only for font families composed from only one word. Georgia will work but Times New Roman will not.
You can see the code here:
or live at http://www.typefolly.com
What is wrong with this? Thanx
You can change your script slightly to replace the quotes that WebKit adds when the font name contains spaces, like this:
$('#selectable1 span').live('mousedown', function() {
var ff = $(this).css("font-family").replace(/\'/g,"");
$("#family").val(ff);
});
You can see a working demo here :)
And here's a RegEx approach pulling the literal value out of style
that's probably easier than anything, but I'm not a RegEx guru, someone feel free to improve this and update the answer (I suck at RegEx, sorry!) This works for all examples you have.
这篇关于jQuery val在Chrome中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!