Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript中的点击问题?_Javascript_Html_Onclick - Fatal编程技术网

javascript中的点击问题?

javascript中的点击问题?,javascript,html,onclick,Javascript,Html,Onclick,如何在href上执行onclick事件,我编写了以下代码,但ot不执行任何操作。我的代码怎么了 <a href="javascript:sendCategoryDetails()" id="maillocation" data-mini="true" data-role="button" data-theme="b" data-inline="true">Send Category Details</a> 使用javascript:document.location.h

如何在href上执行onclick事件,我编写了以下代码,但ot不执行任何操作。我的代码怎么了

<a href="javascript:sendCategoryDetails()" id="maillocation" data-mini="true" data-role="button" data-theme="b" data-inline="true">Send Category Details</a>

使用
javascript:document.location.href=function_name()

选中此项

函数sendCategoryDetails(){
警报(“控制在这里”);
}
100%工作,不知道为什么减票 html


使用

<a href="#" id="maillocation" data-mini="true" data-role="button" data-theme="b" data-inline="true" onClick="sendCategoryDetails()">Send Category Details</a>

javascript: 由于安全原因,在大多数浏览器的新版本中已被禁用,或者已被defualt禁用 发送类别详细信息

    <script>
 function sendCategoryDetails()
 {
   window.location.href("URL");
  }
  </script>

函数sendCategoryDetails()
{
window.location.href(“URL”);
}

请将您的锚html替换为此

<a href="javascript:void(0)" onClick="sendCategoryDetails()" id="maillocation" data-mini="true" data-role="button" data-theme="b" data-inline="true">Send Category Details</a>

或者使用jQuery

<a href="javascript:void(0)"  id="maillocation" data-mini="true" data-role="button" data-theme="b" data-inline="true">Send Category Details</a>

<script>
$(document).ready(function(){
  $('#maillocation').click(function(){
     sendCategoryDetails()
  });
});
</script>

$(文档).ready(函数(){
$(“#邮件位置”)。单击(函数(){
sendCategoryDetails()
});
});

href
属性用于
添加链接
。您不能在
href
上调用该函数

<a href="javascript:void();" id="maillocation" data-mini="true" data-role="button" data-theme="b" data-inline="true" onClick="sendCategoryDetails()">Send Category Details</a>

href=“#”
将发布相同的页面。它会在您的url中添加“不好”


href=“javascript:void();”
使用此选项可避免由于页面发回而使用下面的行
。此链接未显示您的警报消息。在此处工作正常:此代码适用于我如果您的sendCategoryDetails()位于js文件中的正确位置,则您的代码将完美工作。您确定没有将它包装在某个onload()函数中,并且正确地包含了相关的js文件吗?看见
<a href="javascript:void(0)" onClick="sendCategoryDetails()" id="maillocation" data-mini="true" data-role="button" data-theme="b" data-inline="true">Send Category Details</a>
<a href="javascript:void(0)"  id="maillocation" data-mini="true" data-role="button" data-theme="b" data-inline="true">Send Category Details</a>

<script>
$(document).ready(function(){
  $('#maillocation').click(function(){
     sendCategoryDetails()
  });
});
</script>
<a href="javascript:void();" id="maillocation" data-mini="true" data-role="button" data-theme="b" data-inline="true" onClick="sendCategoryDetails()">Send Category Details</a>