[英]JavaScript all possible characters after string
I'm writing a script for a website I'm currently building. 我正在为当前正在构建的网站编写脚本。
var ownerForm = $('#item_owner_form_');
ownerForm.submit(function(ev) {
//$.ajax({
//'url': 'checklist_changeowner.php',
//'type': 'GET',
//'dataType': 'json',
//'data': {owner: blabla, item: blablbalba, checklist: blabla},
//'success': function() {
//
//}
//});
alert(ownerForm.serialize());
ev.preventDefault();
});
As you've probably already seen, I've set a fixed id for the ownerform (in this case #item_owner_form_) However, I am creating lots of forms through PHP and this is not what I'm looking for. 正如您可能已经看到的那样,我为ownerform设置了固定的ID(在本例中为#item_owner_form_)。但是,我正在通过PHP创建许多表单,而这并不是我想要的。 For example, a form that will be generated could be identified as #item_owner_form_42 or as #item_owner_form_913.
例如,将要生成的表单可以标识为#item_owner_form_42或#item_owner_form_913。
Is there a universal character to make sure the ownerForm variable will use all of the forms that start with #item_owner_form_ ? 是否有通用字符来确保ownerForm变量将使用以#item_owner_form_开头的所有形式? Help would be much appreciated!
帮助将不胜感激!
You class
for that. 你为此而
class
。 It can be common for many(similar) elements. 对于许多(相似)元素而言,这可能是常见的。
So, your all forms would look like this, 因此,您的所有表格将如下所示:
<form id="item_owner_form_1" class="commonItemForm">
</form>
<form id="item_owner_form_2" class="commonItemForm">
</form>
And use the class in jQuery like this, 并使用jQuery这样的类,
$('.commonItemForm').submit(function(ev) {
alert($(this).serialize());
ev.preventDefault();
// This function will get triggered for every form which has commonItemForm class.
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.