亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從鏈接運行腳本

從鏈接運行腳本

PHP
肥皂起泡泡 2022-06-17 10:45:08
我有以下腳本在 div 中顯示我的信息,它工作得很好,但有一個按鈕......我試圖讓它從一個鏈接走,我嘗試了很多方法,但沒有,有什么想法嗎?<script>function showCustomer(str) {  var xhttp;      if (str == "") {    document.getElementById("contenido").innerHTML = "";    return;  }  xhttp = new XMLHttpRequest();  xhttp.onreadystatechange = function() {    if (this.readyState == 4 && this.status == 200) {      document.getElementById("contenido").innerHTML = this.responseText;    }  };  xhttp.open("GET", "getcustomer.php?q="+str, true);  history.pushState(null, "", str+ ".xhttp");  xhttp.send();}</script><input type='button' value='6df67913c1' onclick='showCustomer(this.value);' />
查看完整描述

3 回答

?
POPMUISE

TA貢獻1765條經驗 獲得超5個贊

你必須做這樣的事情


const myLinkButton = document.getElementById('my-Link-button')

  ;

myLinkButton.onclick=e=>

  { 

  e.preventDefault()  // -> disable link action for new url

  console.log( myLinkButton.dataset.value )

  }

<a href="#" data-value="6df67913c1" id="my-Link-button" >button by link</a>


查看完整回答
反對 回復 2022-06-17
?
qq_笑_17

TA貢獻1818條經驗 獲得超7個贊

利用<a href="JavaScript: void (0)" onclick="callYourFunction()>link<\a>



查看完整回答
反對 回復 2022-06-17
?
慕妹3146593

TA貢獻1820條經驗 獲得超9個贊

你可以這樣做。


    <script>

        function showCustomer(element) {

          const str = element.getAttribute('data-value')

          var xhttp;    

          if (str == "") {

            document.getElementById("contenido").innerHTML = "";

            return;

          }

          xhttp = new XMLHttpRequest();

          xhttp.onreadystatechange = function() {

            if (this.readyState == 4 && this.status == 200) {

              document.getElementById("contenido").innerHTML = this.responseText;

            }

          };

          xhttp.open("GET", "getcustomer.php?q="+str, true);

          history.pushState(null, "", str+ ".xhttp");

          xhttp.send();

        }

    </script>

    <a href="#" onclick="showCustomer(this)" data-value="6df67913c1">Same, from link</a>



查看完整回答
反對 回復 2022-06-17
  • 3 回答
  • 0 關注
  • 138 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號