function cancelFullScreen(el) { var requestMethod = el.cancelFullScreen||el.webkitCancelFullScreen||el.mozCancelFullScreen||el.exitFullscreen; if (requestMethod) { // cancel full screen. requestMethod.call(el); } else if (typeof window.ActiveXObject !== "undefined") { // Older IE. var wscript = new ActiveXObject("WScript.Shell"); if (wscript !== null) { wscript.SendKeys("{F11}"); } } }
$('input:button[id="addrow"]').click(function(){
var secondlast = $('table tr:last').prev('tr');
var newClone = secondlast.clone();
// find all the inputs within your new clone and for each one of those
newClone.find('input').each(function() {
var currentNameAttr = $(this).attr('name'); // get the current name attribute
// construct a new name attribute using regular expressions
// the match is divided into three groups (indicated by parentheses)
// p1 will be 'v',p2 will be the number,p3 will be the remainder of the string
var newNameAttr = currentNameAttr.replace(/^(v)(\d+)(.*)$/,function(match,p1,p2,p3) {
return p1+(parseInt(p2)+1)+p3;
});
$(this).attr('name',newNameAttr); // set the incremented name attribute
});
// insert after is I assume what you want
newClone.insertAfter(secondlast);
});
编辑
// you Could also simply increment any digit you find as Batman indicated
var newNameAttr = currentNameAttr.replace(/\d+/,function(match) {
return (parseInt(match)+1);
});
javascript – 如何使用jQuery访问元素id和其他属性?
我有JavaScript方法,当提交表单的特定类(mcb)时,它会起作用:
function BindCloseMessage() {
$(".mcb").submit(function(event) {
alert("closing..."); //Here I want to get the id of form
event.preventDefault();
});
}
代替警报调用,我需要访问其提交被调用的表单的id.我该怎么做?更好的是访问任何属性的提示……
谢谢
解决方法:
提交表单的ID将是
this.id
或者在jQuery中
$(this).attr('id') //although why type the extra letters?