生成的表单不喜欢javascript更改字段值函数 [英] Generated form not liking javascript change field value function
问题描述
我以前曾经帮助使用jquery工作来获得javscript函数 - 请参阅:
JS Fiddle工作示例
$ b
$([name ='COLUMN35']] ).on('change',function(){var val = $(this).val(); var reverseVal =(val =='Yes'?'No':'Yes')$(input [value ='+ reverseVal +']:not([name ='COLUMN35']))。prop('checked',true);});
< pre class =snippet-code-html lang-html prettyprint-override> < script src =https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery选项1< / span>< br />< form>< label>< input type =radioname =option1id =option1Yesvalue =是>是< / label>< label>< input type =r选项2< / span>< br />< >< label>< input type =radioname =option2id =option2Yesvalue =Yes>是< / label>< label>< input type = option2id =option2Novalue =No>否< / label>< hr />< span>退订所有< / span>< br />< label><输入type =radioname =COLUMN35id =unsubYesvalue =Yes>是< / label>< label>< input type =radioname =COLUMN35id =unsubNovalue =否>否< / label>< br />< br />< input type =submitvalue =submit>< / form>
将相同的代码放入生成的表单页面后,我不确定它为什么不起作用 - 请参阅:
Webform with code not working
不幸的是,我无法编辑任何的表单元素,因为它们是自动生成的,但希望有人可能有不同的想法来实现 - 通常情况下,更好的EG目标相关的ID改变,也许不使用jquery
eg (b)>
$(document).ready(function(){
$([name ='COLUMN35'])。 on('change',function(){
var val = $(this).val();
var reverseVal =(val =='Yes'?'No':'Yes')
$(input [value ='+ reverseVal +']:not([name ='COLUMN35' ]))。prop('checked',true);
});
});
I was previously helped to get a javscript function using jquery working - see : JS Fiddle working example
$("[name='COLUMN35']").on('change', function() {
var val = $(this).val();
var reverseVal = (val == 'Yes' ? 'No' : 'Yes')
$("input[value='" + reverseVal + "']:not([name='COLUMN35'])").prop('checked', true);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span>Option 1</span><br />
<form>
<label><input type="radio" name="option1" id="option1Yes" value="Yes">Yes</label>
<label><input type="radio" name="option1" id="option1No" value="No">No</label>
<br /><br />
<span>Option 2</span><br />
<label><input type="radio" name="option2" id="option2Yes" value="Yes">Yes
</label>
<label><input type="radio" name="option2" id="option2No" value="No">No</label>
<hr />
<span>Unsubscribe from all</span><br />
<label><input type="radio" name="COLUMN35" id="unsubYes" value="Yes">Yes</label>
<label><input type="radio" name="COLUMN35" id="unsubNo" value="No">No</label>
<br /><br />
<input type="submit" value="submit">
</form>
Upon implmenting that same code into the generated form page i am not sure why it does not work - see: Webform with code not working
Unfortunately I am not able to edit the any of the form elements as they are generated automatically but hoping someone might have a different idea to implement - usually the messier the better E.G target the relevant ids to change and maybe not using jquery
try putting your code in $(document).ready(function(){})
eg
$(document).ready(function(){
$("[name='COLUMN35']").on('change', function(){
var val = $(this).val();
var reverseVal = (val == 'Yes' ? 'No' : 'Yes')
$("input[value='"+reverseVal+"']:not([name='COLUMN35'])").prop('checked', true);
});
});
这篇关于生成的表单不喜欢javascript更改字段值函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!