如何将此信息从按钮选择(字体大小)传输到php脚本,然后将信息保存到mysql? 这是一个段落。//txt段落 小号//按钮一 更大的//按钮二 大//按钮三 函数myFunction(){//functon到第一个按钮 document.getElementById(“myP”).style.fontSize=“x-small”; } 函数myFunction2(){//functon到第二个按钮 document.getElementById(“myP”).style.fontSize=“x-large”; } 函数myFunction3(){//functon到第三个按钮 document.getElementById(“myP”).style.fontSize=“xx大”; }
为了整洁起见,我会首先更新脚本以获取一个变量,这样您只需要编写一次,比如如何将此信息从按钮选择(字体大小)传输到php脚本,然后将信息保存到mysql? 这是一个段落。//txt段落 小号//按钮一 更大的//按钮二 大//按钮三 函数myFunction(){//functon到第一个按钮 document.getElementById(“myP”).style.fontSize=“x-small”; } 函数myFunction2(){//functon到第二个按钮 document.getElementById(“myP”).style.fontSize=“x-large”; } 函数myFunction3(){//functon到第三个按钮 document.getElementById(“myP”).style.fontSize=“xx大”; },php,css,html,Php,Css,Html,为了整洁起见,我会首先更新脚本以获取一个变量,这样您只需要编写一次,比如 <!DOCTYPE html> <html><body> <p id="myP">This is a paragraph.</p> // txt paragraph <button type="button" onclick="myFunction()">Small</button> // button one <button
<!DOCTYPE html>
<html><body>
<p id="myP">This is a paragraph.</p> // txt paragraph
<button type="button" onclick="myFunction()">Small</button> // button one
<button type="button" onclick="myFunction2()">Bigger</button> // button two
<button type="button" onclick="myFunction3()">Large</button> // button three
<script>
function myFunction() { // functon to first button
document.getElementById("myP").style.fontSize = "x-small";
}
</script>
<script>
function myFunction2() {// functon to second button
document.getElementById("myP").style.fontSize = "x-large";
}
</script>
<script>
function myFunction3() { // functon to third button
document.getElementById("myP").style.fontSize = "xx-large";
}
</script>
</body>
</html>
注意:您需要将jquery添加到代码中才能使用ajax,并且需要了解ajax,请访问:了解更多信息提供关于您的问题以及代码的更多详细信息
<button type="button" onclick="myFunction('small')">Small</button>
<button type="button" onclick="myFunction('bigger')">Bigger</button>
<script>
function myfunction(fontSize){
$.ajax({
url: '/some/url',
type: 'POST',
data: { var1: fontSize } ,
contentType: 'application/json; charset=utf-8',
success: function (response) {
// reload items on page if required;
},
error: function () {
// do something with your error
}
});
}
</script>
data: { var1: fontSize, var2: userId, var3: csrfToken }