简体   繁体   English

Javascript onClick 不执行

[英]Javascript onClick doesn't execute

I created a button code.我创建了一个按钮代码。 See below:见下文:

<input type="button" style="background-color: red" value="Login" onclick="tmpl_login_frm();" href="javascript:void(0);" data-reveal-id="tmpl_reg_login_container">

When I click on the button the button is not working and it doesn't execute the javascript.当我单击按钮时,该按钮不起作用并且它不执行 javascript。 Can you please help me fix it?你能帮我修一下吗?

I would like to show this button anywhere at post or page.我想在帖子或页面的任何位置显示此按钮。

Your code works perfectly fine.您的代码运行良好。 I added below javascript and it worked as expected.我在 javascript 下面添加了它,它按预期工作。 Please try adding this to your code and see if it works -请尝试将此添加到您的代码中,看看它是否有效 -

<input type="button" style="background-color: red" value="Login" onclick="tmpl_login_frm();" href="javascript:void(0);" data-reveal-id="tmpl_reg_login_container">

<script>
    function tmpl_login_frm() {
        console.log('vivek');
    }
</script>

But yes you should not use href with inputs as this is an invalid HTML.但是是的,您不应该将 href 与输入一起使用,因为这是无效的 HTML。

I tried this and it is working.我试过这个,它正在工作。 Please check.请检查。 Ref: https://jsfiddle.net/hcumg4bq/1/参考: https : //jsfiddle.net/hcumg4bq/1/

<input type="button" style="background-color: red" value="Login" onclick="tmpl_login_frm();" data-reveal-id="tmpl_reg_login_container">
    <script>
        function tmpl_login_frm() {
            window.alert("I'm clicked");
        }
    </script>
<input type="button" style="background-color: red" value="Login" onclick="tmpl_login_frm();" href="javascript:void(0);" data-reveal-id="tmpl_reg_login_container">
<script>
    function tmpl_login_frm() {
       alert("tmpl_login_frm");
    }
</script>

this code is work for me这段代码对我有用

your Code worked fine for me...你的代码对我来说很好用......
maybe it's because your navigator doesn't allow alerts !!也许是因为您的导航器不允许警报!

Open Chrome.打开 Chrome。
In the upper right corner of the browser window, click the Chrome menu ☰在浏览器窗口的右上角,点击 Chrome 菜单 ☰
Click Settings > Show advanced settings.单击设置 > 显示高级设置。
In the "Privacy" section, click Content settings.在“隐私”部分,单击内容设置。
In the dialog that appears, go to "Notifications" and choose the following:在出现的对话框中,转到“通知”并选择以下内容:
Allow all sites to show notifications: You'll automatically see notifications from all websites.允许所有网站显示通知:您将自动看到来自所有网站的通知。

 <input type="button" style="background-color: red" value="Login" onclick="tmpl_login_frm();" data-reveal-id="tmpl_reg_login_container"> <script> function tmpl_login_frm() { window.alert("I'm clicked"); } </script>

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

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