简体   繁体   English

切换按钮设置输入类型隐藏字段

[英]Toggle Button to set input type hidden field

I need to have a toggle button where ... 我需要有一个切换按钮,...

JQuery and Php needed here? 这里需要JQuery和Php吗?

If I click it one...the input hidden will be: 如果我单击它...隐藏的输入将是:

// Display this one if $myPhpVar isset
<input type="hidden" name="myHidden" id="myHidden" value="<?php echo $myPhpVar ?>" /> 

and if I click again: 如果我再次单击:

// Display this one if $myPhpVar is not empty
<input type="hidden" name="myHidden" id="myHidden" value="" /> 

Hope I've explaining properly. 希望我能正确解释。

UPDATE: What I want to do is that If $myVar is not empty when I click button X then it will set the value to blank. 更新:我想做的是,如果当我单击按钮X时$ myVar不为空,则它将值设置为空白。

Here you go : 干得好 :

var phpvar = "<? php echo $myPhpVar ?>";

$('#myButton').toggle(function() {
$('myHidden').val(phpvar);
} ,function() {
$('myHidden').val('');
});

and example fiddle : http://jsfiddle.net/8dwNf/1/ 和小提琴示例: http : //jsfiddle.net/8dwNf/1/

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

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