Ani*_*Ani 2 php smarty dom-events
我正在使用 Smarty 模板创建一个调查表单,在其中我想附加一个带有特定问题单选按钮的事件,以便在单击其中任何一个按钮时弹出一条消息。
所以我想在它们上添加一个单击/更改事件侦听器,但不知道如何使用 PHP 来做到这一点。由于我事先不知道单选按钮 id(它们是动态生成的),所以我不确定是否可以在此处使用 JavaScript。有什么解决方案/建议吗?
Google 搜索返回了为 Android 和 JavaScript 添加事件侦听器的各种答案,但毫无用处!
只需向单选按钮添加一个类,然后使用 JavaScript/JQuery,您就可以根据需要向输入添加事件侦听器。
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="myjsfile.js"></script>
<input type="radio" class="clickyradio" />
<input type="radio" class="clickyradio" />
<input type="radio" class="clickyradio" />
Run Code Online (Sandbox Code Playgroud)
现在在文件 myjsfile.js 中
$(document).ready(function() {
$('.clickyradio').click(function() {
// whatever you want to happen when it gets clicked
// "this" keyword will refer to the input element that got clicked
});
});
Run Code Online (Sandbox Code Playgroud)
如果您需要单击来与服务器进行某些通信,请在单击事件处理程序中放置 ajax 调用。
| 归档时间: |
|
| 查看次数: |
18516 次 |
| 最近记录: |