我想问一下从变量中使用选择器
首先我有:
function check()
{
$('.info input, .info select').each(function(n, element){
if ($(element).val()=='')
alert('empty');
});
}
Run Code Online (Sandbox Code Playgroud)
并称之为
$('input')change(check);
Run Code Online (Sandbox Code Playgroud)
他们工作得很好.
但是现在我想将一些值传递给函数以使其成为动态的,就像
$('input')change(check('.info'));
Run Code Online (Sandbox Code Playgroud)
并将功能更改为
function check(sel) {
$(sel +' input, '+ sel + ' select').each(function(n, element){
if ($(element).val()=='')
alert('empty');
});
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.请帮忙..谢谢,
nagut
我想在一个页面中插入多个滑块.我有一块我想重用的代码,但它会插入2个DIV id=slider...
是否可以找到第二个元素id=slider并重命名为id=slider01?
BR.安德斯
我的目的是比较名字和img元素的标题,并在名字与img-element的标题匹配时插入姓氏.但在编程之前,我想问你一个问题.
有没有更简单的方法来创建一个包含我所选择的名字和姓氏的新数组列表?如果我有大约100个新阵列,每个阵列都包含名字和姓氏,那将是非常不方便的.
var username = new Array();
username[0] = new Array();
username[0]["first name"] = "daniel";
username[0]["last name"] = "obrian";
username[1] = new Array();
username[1]["first name"] = "stuart";
username[1]["lastname"] = "oconner";Run Code Online (Sandbox Code Playgroud)
先感谢您.
说有一个字符串
"......宽度= 600高度= 1200 ......".
我希望在"width="之前和之后得到字符串" ",这是600.
我怎样才能做到这一点?
我正在尝试计算元素的当前样式:
function cssIsLoaded(c) {
if (window.getComputedStyle) {
return window.getComputedStyle(c, null).display === "none";
}
else if (c.currentStyle) {
}
return true;
}
(function() {
var cssload = document.createElement("div");
cssload.className = "_css_loaded";
checkLoaded();
function checkLoaded() {
if (!cssIsLoaded(cssload)) setTimeout(function() {
checkLoaded();
}, 20);
else blalbalblbalbalablbal();
}
})();
Run Code Online (Sandbox Code Playgroud)
IE没有进入第二个条件,c.currentStyle是null ...为什么?
正如标题所说,我无法开始.attr('checked', false)使用IE6.我正在克隆一些HTML,然后在将新克隆的HTML分配给一个元素之前,我运行它并取消检查新克隆部分中的所有复选框,这在除IE 6之外的所有浏览器中都能正常工作.
这是代码:
//give each input and select a custom id
clone.find('input, select').each( function( i ) {
//get the id attribute
var id = $(this).attr('id');
//uncheck all of the tick boxes
$(this).attr('checked', '');
//get the name attribute
var name = $(this).attr('name');
$(this).attr('name', name+"_"+count)
$(this).attr('id', id+"_"+count+"_"+i)
});
//append the newly created area to the area wrapper
clone.appendTo('[data-custom="area_wrapper"]');
Run Code Online (Sandbox Code Playgroud)
有什么方法可以解决这个问题吗?
如果用户单击浏览器的后退按钮,则我需要出现提示并要求确认.如果用户单击"确定",则应该导航到xx.html.如果用户点击"取消",则应该阻止导航.我怎样才能做到这一点?
注意:我已经尝试过该onbeforeunload方法,但它适用于所有导航操作.例如,单击页面上的链接也将触发此事件并向用户显示消息.
从来没有在javascript字符串中播放变音符号或特殊字符.我的问题是如何删除它们?
例如我在javascript中有这个:
var oldstr = "Bayern München";
var str = oldstr.split(' ').join('-');
Run Code Online (Sandbox Code Playgroud)
结果是拜仁慕尼黑很容易,但现在我想要移除变音符号或特殊搜索:
Real SportingdeGijón.
我怎么能意识到这一点?
亲切的问候,
坦率
我只想添加数字(货币,如果你愿意),像1.5和1.47一样,并使它等于1.97.
这是如何完成的?我不知道我不知道怎么做!:)
var discountAmount = 0;
var ogCookie = < %= strJsonCookie % >
for (var i = 0; i < ogCookie.products.length; i++) {
discountAmount = parseFloat(discountAmount) + parseFloat(ogCookie.products[i].discount_amount);
}
alert(discountAmount);
Run Code Online (Sandbox Code Playgroud) 如果 if((hit.transform != transform)是手段if hit.transform is Not transform,那么我该如何检查该陈述是否正确.if(hit.transform = transform)似乎不起作用.