【问题标题】:get the dropdown particular selected value and dispaly confirm box获取下拉特定选定值并显示确认框
【发布时间】:2013-10-24 10:37:20
【问题描述】:

我有会员状态选择框,我有打开、阅读、关闭选项。所以当我选择打开或阅读并单击更新按钮时,它会更新一些东西。我选择关闭它会显示对话框(你确定要关闭这个)如果是,它会进入某个页面或没有页面。(我只想显示确认框的特定值(仅限 22)。 任何人都可以帮助这个(js或jquery)。它是聪明的应用程序

这是我的代码

<html>
<head> 
    <script type="text/javascript"> 
        function showClose() { 
            var val = document.getElementById('sel_state').value; 
            if (val == '22') { 
                var state = confirm("Are you sure want to change member status??"); 
                if (state == true) { 
                    alert('yes'); 
                } else { 
                    alert('no'); 
                } 
            } else { 
                alert('no'); 
            } 
        } 
    </script> 
</head>
<body> 
<form method="post" action="/admin/member-modify-{$member->id}">
    <label>Member state</label>    
    <select name="sel_state" class="validate" id="sel_state"> 
        <option value=1>open</option> 
        <option value=2>read</option> 
        <option value=22>close</option> 
    </select> 
    <input name="submit" value="Validate" id="member_state_submit" type="submit" class="submit" Onclick="showClose();" /> 
</form> 
</body> 
</html> 

【问题讨论】:

标签: javascript jquery mysql smarty


【解决方案1】:

您所要做的就是将您的 JS 代码包装在 {literal}{/literal} 标记中,如下所示:

{literal}
<script type="text/javascript"> 
    function showClose() { 
        var val = document.getElementById('sel_state').value; 
        if (val=='22') { 
            var state = confirm ("Are you sure want to change member status??");
            if (state == true) { 
                alert('yes'); 
            } else { 
                alert('no'); 
            } 
        } else { 
            alert('no'); 
        } 
    } 
</script>
{/literal}

在 Smarty 中,{literal}{/literal} 标签内的任何内容都不会被解释,而是按原样显示。这将避免干扰模板分隔符语法。检查documentation

【讨论】:

    【解决方案2】:

    jquery 很简单

    var value = $('#selector').text()
    if (value == 22){
       //do something here
    }
    

    【讨论】:

    • 与java脚本相同,但无法正常工作。请您解释得更清楚
    • 您正在使用选择框,所以如果您需要价值,请使用val(),如果您需要选项文本,请使用text()
    • 我这样添加了jquery
    • $(document).ready(function(){ $('#member_state_submit').click(function(){ var value = $('#sel_state').value(); if ( value == 22){ var result = window.confirm('Are you sure?'); if(result){ alert('yes'); } else{ alert('no;') } } }); }) ;
    猜你喜欢
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-02
    • 1970-01-01
    相关资源
    最近更新 更多