简体   繁体   English

target_blank在<a>标记中</a>不起作用

[英]target_blank not working in <a> tag

I have a button.when click this go to the particular function. 我有一个按钮。单击此按钮可转到特定功能。 In the presence onclick target_blank not working. 存在onclick target_blank无效。

Any solution 任何解决方案

   <a onclick="editView('<?php echo $detail->id;?>')" class="btn button_style" title="Edit" target="_blank">Edit</a>

script 脚本

   function editView(id)
{
    var form = document.createElement("form");
    var input1 = document.createElement("input"); 

    form.action = "<?echo base_url()?>home/editData";
    form.method = "post"

    input1.name = "id";
    input1.type = "hidden";
    input1.value = id;
    form.appendChild(input1);

    document.body.appendChild(form);

    form.submit();
}

target="_blank" causes a link to open in a new window. target="_blank"使链接在新窗口中打开。

You don't have a link. 您没有链接。 You have an anchor element with an onclick attribute which runs some JavaScript. 您有一个带有onclick属性的锚元素,该元素运行一些JavaScript。 (You should be using a <button> element since you don't have an actual link, better yet , have a link to a URL which replicates the effects of the JS server side). (您应该使用<button>元素,因为您没有实际的链接, 更好的是 ,具有指向URL的链接,该URL复制了JS服务器端的效果)。

In order to get it to open a new window, you will have to modify your JavaScript (we can't see the editView function so it is hard to say precisely how) to make use of the open method . 为了使其打开新窗口,您必须修改JavaScript(我们看不到editView函数,因此很难确切地说出方法)以使用open方法


You are generating a form which takes no user input and just has fixed data. 您正在生成一个无需用户输入且仅包含固定数据的表单。 The easiest way to deal with this is to just us a form in the first place. 解决此问题的最简单方法是首先只为我们提供一个表单。

<form method="post" 
      action="<?php echo base_url(); ?>home/editData"
      target="_blank">
    <input type="hidden" name="id" value="<?php echo $detail->id;?>">
    <button class="btn button_style">Edit</button>
</form>

Forget about JavaScript. 忘记JavaScript。 Add CSS to style the form (eg display: inline; margin: 0; padding: 0 ) and button to taste. 添加CSS来设置表单样式(例如display: inline; margin: 0; padding: 0 )和按钮以进行样式设置。

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

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