简体   繁体   English

在Drupal中使用Jquery编辑隐藏的表单字段

[英]Editing hidden form field with Jquery in Drupal

Currently I'm trying to edit a hidden form with the command: 目前,我正在尝试使用以下命令编辑隐藏的表单:

 jQuery(document).ready(function(){    
    jQuery("#test").val("hi");
 });

This is inside an inline drupal_add_js. 这在内联drupal_add_js中。

When the form 'test' is a normal textfield, this works. 当表单“ test”是普通文本字段时,此方法有效。 When it is hidden, this does not work. 当它被隐藏时,这是行不通的。 I'm currently using Drupal 7's webform module to create the form. 我目前正在使用Drupal 7的webform模块创建表单。 I've read dozens of stackoverflow questions regarding populating hidden fields but I haven't gotten anything to work. 我已经阅读了许多有关填充隐藏字段的stackoverflow问题,但是我什么都没做。 I'm hoping that its just something that is syntactically different for hidden fields, but most likely its something in drupal I don't know about. 我希望它与隐藏字段在语法上有所不同,但很可能是我不知道的drupal中的某些东西。

请尝试:

jQuery("input[name=test]").val("hi");

i am really not aware of coding style in Drupal , but if u want i can suggest you in basic jQuery way, hope this will b helpful for u :) 我真的不知道Drupal的编码风格,但是如果您希望我可以用基本的jQuery方式建议您,希望对您有所帮助:)

HTML 的HTML

<form name="testform" method="POST" action ="#">
    <input type="hidden" name="hiddenInput" id="hiddenInput">
    Hii
    <input type="submit" name="Go" >
</form>

jQuery jQuery的

$('form').submit{(
    alert('Submitted');
    var hid=$('input[type="hidden"]').val('HiddenText');
    alert(hid.val);
    return false;
    });

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM