[英]Can we use onclientclick in PHP?
<script type="text/javascript">
function changeText2(){
var userInput = document.getElementById('userInput').value;
document.getElementById('boldStuff2').innerHTML = userInput;
return confirm('Hello!');
//return true;
}
</script>
<form method="get">
<p>Welcome to the site <b id='boldStuff2'>dude</b> </p>
<input type='text' id='userInput' value='Enter Text Here' />
<input type='button' OnClientClick="return changeText2()" value='Change Text'/>
</form>
這在PHP中可行嗎? 我嘗試過,但出現錯誤。 請提出解決方案。
不完全是。
PHP沒有ASP.NET那樣復雜的模板引擎。
您可以直接直接使用HTML onclick
屬性。 無需在客戶端上使用其他名稱的名稱,因為不會有名稱相同的服務器端屬性。
但是,最好的做法是編寫簡潔的JS並以編程方式綁定事件處理程序 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.