gpt4 book ai didi

javascript - 激活弹出窗口(HTML、PHP、Javascript/Jquery)

转载 作者:行者123 更新时间:2023-11-30 07:31:22 25 4
gpt4 key购买 nike

今天我有一个简单的请求要问你们这些聪明人。我想要做的是在 PHP 标签内激活一个弹出窗口。我已经测试过弹出窗口是否可以自行运行,确实如此。我的问题是按钮,我在其他地方使用了相同的设置,但这次没有雪茄。我也试过回显 PHP 标签内的按钮,但没有任何反应。

我的代码:

<!doctype html>
<html lang="en">
<head>

<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="Lib\JqueryUIcss.css">
<script src="Lib\Jquerylib.js"></script>
<script src="Lib\JqueryUI.js"></script>

</head>
<body>

<button type=" button" class="LeButton"> Clicky Clicky!</button>

<?php
if(isset($_POST['LeButton'])){

echo'<script> $(function() { $( "#dialog" ).dialog(); }); </script>';
echo'<div id="dialog" title="Basic dialog">';
echo'<p>Image:</p>'; </div>';}
?>
</body>
</html>

我也尝试将它指定为一个函数,并将 onclick() 添加到按钮以调用该函数,但也没有任何反应。请注意,这是我第一次使用 Javascript/jQuery

最佳答案

我(和蔼地)对 echo 笑了笑<script>部分。

请允许我给你写一段代码,附上解释和文档:

HTML 按钮:

<button type="button" id="LeButton" class="LeButton"> Clicky Clicky! </button>

&

<div id="dialog" title="Basic dialog" style="visibility:hidden"><p>Image:</p> <img src="http://placehold.it/50x50" alt="Placeholder Image" /></div>

解释:

Your button needs an id value. Which is called 'LeButton' in this example.

文档:

https://www.w3schools.com/tags/att_id.asp

jQuery 部分:

<script>
jQuery(document).ready(function() {

/**
* @version 1.0.0.
*
* Do magic on button click 'LeButton'
*/
$("#LeButton").click(function() {
$("#dialog").css("visibility", 'visible'); // make the div visible.
$("#dialog").dialog(); // Post here your code on forexample poping up your modal.
});
});
</script>

解释:

Your tag can be placed on the bottom of your page. Your browser will 'read' the whole page. By saying '(document).ready', your script will be executed once the page has been red by your browser.

For the '.click' part it's a jQuery function you can use. So which means: once id attribute 'LeButton' (#) is clicked, jQuery will execute a function, which will alert text in this case.

文档:

https://api.jquery.com/click/

注意:确保您有 jQuery包含/启用。

链接:

https://jquery.com/download/


来自 Simon Jensen 的笔记:

  • 您应该详细说明 Class 属性用于样式,而Id 属性可以用于任何代码或识别目的,并且是独特的。因此,人们应该小心使用Id 属性,因为某些时候可能会发生冲突。 ID属性用于与“#LeButton”属性交互。

关于javascript - 激活弹出窗口(HTML、PHP、Javascript/Jquery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51839903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com