我该如何添加readonly到特定的<input>?.attr('readonly')不起作用.
我有一个表单输入元素,并希望更改其title属性.这必须很容易,但由于某种原因,我找不到如何做到这一点.这是怎么做的,我应该在哪里以及如何搜索如何做到这一点?
我一直在寻找方法让jQuery自动写入使用html5验证到我的所有输入字段,但我无法告诉它在哪里写它.
我想接受这个
<input type="text" name="first_name" value="" id="freeform_first_name"
maxlength="150">
Run Code Online (Sandbox Code Playgroud)
并在结束标记之前自动添加所需内容
<input type="text" name="first_name" value="" id="freeform_first_name"
maxlength="150" required>
Run Code Online (Sandbox Code Playgroud)
我以为我可以做一些事情
$("input").attr("required", "true");
Run Code Online (Sandbox Code Playgroud)
但它不起作用.任何帮助是极大的赞赏.
我有一个输入框,我希望它被禁用,同时隐藏它以避免在移植表单时出现问题.
到目前为止,我有以下代码来隐藏我的输入:
$(".shownextrow").click(function() {
$(this).closest("tr").next().show().find('.longboxsmall').hide();
});
Run Code Online (Sandbox Code Playgroud)
这是因此隐藏的输入:
<input class="longboxsmall" type="text" />
Run Code Online (Sandbox Code Playgroud)
如何将disabled属性添加到输入?
我不是jQuery的专家,但我试图为我的应用程序创建一个小脚本.我想检查所有复选框,但它无法正常工作.
首先我尝试使用attr,之后我尝试了,prop但我做错了.
我先试了一下:
$("#checkAll").change(function(){
if (! $('input:checkbox').is('checked')) {
$('input:checkbox').attr('checked','checked');
} else {
$('input:checkbox').removeAttr('checked');
}
});
Run Code Online (Sandbox Code Playgroud)
但这没效果.
下一步:这比上面的代码效果更好
$("#checkAll").change(function(){
if (! $('input:checkbox').is('checked')) {
$('input:checkbox').prop('checked',true);
} else {
$('input:checkbox').prop('checked', false);
}
});
Run Code Online (Sandbox Code Playgroud)
这两个例子都不起作用.我试着谷歌搜索答案,但没有成功.
jsFiddle:http://jsfiddle.net/hhZfu/4/
谢谢
现在,这不只是一个有什么区别的问题,我已经做了一些测试(http://jsfiddle.net/ZC3Lf/)修改prop和attr的<form action="/test/"></form>? 与输出是:
1)prop修改测试
Prop:http://fiddle.jshell.net/test/1
Attr:http://fiddle.jshell.net/test/12)Attr修改测试
Prop:http://fiddle.jshell.net/test/1
Attr:/test/13)Attr然后Prop Propification测试
Prop:http://fiddle.jshell.net/test/11
Attr:http://fiddle.jshell.net/test/114)Prop然后Attr修改测试
Prop:http://fiddle.jshell.net/test/11
Attr:http://fiddle.jshell.net/test/11
现在我对一些事情感到困惑,据我所知:
Prop:在通过JavaScript
Attr进行任何修改后的当前状态值:在页面加载的html中定义的值.
现在如果这是正确的,
prop似乎使action完全合格,相反为什么修改属性不?propin 1)修改属性,对我来说没有意义?attrin 2)修改属性,它们是否意味着以这种方式链接?HTML
JavaScript的
var element = $('form');
var property = 'action';
/*You should not need to modify below this line */
var body = …Run Code Online (Sandbox Code Playgroud) 当我将一个函数绑定到一个复选框元素,如:
$("#myCheckbox").click( function() {
alert($(this).is(":checked"));
});
Run Code Online (Sandbox Code Playgroud)
复选框在触发事件之前更改其已检查的属性,这是正常行为,并给出反向结果.
但是,当我这样做时:
$("#myCheckbox").click();
Run Code Online (Sandbox Code Playgroud)
触发事件后,复选框会更改其检查属性.
我的问题是,有没有办法从jQuery触发click事件,就像普通点击一样(第一个场景)?
PS:我已经尝试过trigger('click');
我想为使用jquery通过查询字符串传递的任何内容设置一个下拉框.
如何将选定的属性添加到选项中,使"TEXT"值等于查询字符串中的某个参数?
$(document).ready(function() {
var cat = $.jqURL.get('category');
if (cat != null) {
cat = $.URLDecode(cat);
var $dd = $('#cbCategory');
var $options = $('option', $dd);
$options.each(function() {
if ($(this).text() == cat)
$(this).select(); // This is where my problem is
});
};
});
Run Code Online (Sandbox Code Playgroud) 我在一些地方看到.attr()用于jQuery.在一些地方.prop()被使用.但我搜索了SO和谷歌我很困惑.请告诉我这两者之间的确切区别以及何时使用它们.
我已经看到以下链接 jQuery attr与prop,有一个道具列表? jQuery attr vs prop?
但我没有得到答案.请帮帮我.谢谢.
在给出downvote之前请说明原因,然后我将在下一篇文章中更正.
jquery ×10
javascript ×4
attr ×2
prop ×2
attributes ×1
checkbox ×1
click ×1
forms ×1
input ×1
ischecked ×1
onclick ×1
validation ×1