gpt4 book ai didi

jquery - JQuery 和论坛

转载 作者:行者123 更新时间:2023-12-01 07:58:56 25 4
gpt4 key购买 nike

使用JQuery会怎样使用

$("button").click(function(event){

填充论坛变量。

我想要一个按钮,如果用户单击它,它将确定评论的去向。这样我就可以使用 Image_ID 将每个评论链接到单独的图像。我想让用户不必像下面的论坛当前需要的那样输入 Image_ID 号码。

  <input type="text" name="Image_ID" message="Please enter Account Here." 
validateat="onSubmit" required="yes" id="Image_ID" size="10"
maxlength="60">
</input>

以上是我需要自动化输入的手动输入部分。

        <cfform name="InsertComments" id="InsertComments">
<fieldset>
<div id="container">
<div id="mainContent">


<textarea name="Remarks" cols="55" rows="4" label="Tour Description"
required="yes" validateat="OnSubmit" message="Please enter your comment here"
enabled="no">
</textarea>
<input type="text" name="Image_ID" message="Please enter Account Here."
validateat="onSubmit" required="yes" id="Image_ID" size="10"
maxlength="60">
</input>
<input type="submit" name="insertComments" value="Insert Comments" id="submit">
</input>
</div>
</div>
</fieldset>
</cfform>
<cfif IsDefined("form.InsertComments")>

<cfquery datasource="AccessTest">
INSERT INTO CommentsDB (Remarks, Image_ID, Date_Time )
VALUES
(<cfqueryparam value="#form.Remarks#" cfsqltype="CF_SQL_LONGVARCHAR">

, <cfqueryparam value="#form.Image_ID#" cfsqltype="cf_sql_integer">

, <cfqueryparam value="#now()#" cfsqltype="cf_sql_timestamp">

)
</cfquery>

</cfif>

我的总代码如下;

    <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>
Untitled Document
</title>

<cfquery datasource="AccessTest" name="qTest">
SELECT P.Account, P.Image, P.Image_ID, C.Remarks, C.Users, C.Accounts, C.Date_Time
FROM PictureDB AS P
INNER JOIN CommentsDB AS C
ON C.Image_ID = P.Image_ID
ORDER BY P.Image_ID
</cfquery>

<script src="http://code.jquery.com/jquery-2.0.3.js">

</script>

<script>
$(document).ready(function(){
var images = {
<cfoutput query="qTest" group="Image_ID">
"#qTest.Image_ID#": {
"image": "#qTest.Image#",
"remarks": [
<cfoutput>
"#qTest.Users#, #qTest.Date_Time# <br> #qTest.Remarks# <br> </br>",
</cfoutput>
]
},
</cfoutput>
};
$("button").click(function(event){
event.preventDefault();
var id = $(this).data("id");
var src = images[id].image;
var desc = images[id].remarks.toString();

$("#theImage").attr("src", src).removeClass("hide");
$("#theDescription").html(desc).removeClass("hide");
});
});
</script>
</head>

<body>



<cfoutput query="qTest" group="Account">
<button data-id="#qTest.Image_ID#">
#qTest.Account#

</button>

</cfoutput>

<cfform name="InsertComments" id="InsertComments">
<fieldset>
<div id="container">
<div id="mainContent">


<textarea name="Remarks" cols="55" rows="4" label="Tour Description"
required="yes" validateat="OnSubmit" message="Please enter your comment here"
enabled="no">
</textarea>
<input type="text" name="Image_ID" message="Please enter Account Here."
validateat="onSubmit" required="yes" id="Image_ID" size="10"
maxlength="60">
</input>
<input type="submit" name="insertComments" value="Insert Comments" id="submit">
</input>
</div>
</div>
</fieldset>
</cfform>
<cfif IsDefined("form.InsertComments")>

<cfquery datasource="AccessTest">
INSERT INTO CommentsDB (Remarks, Image_ID, Date_Time )
VALUES
(<cfqueryparam value="#form.Remarks#" cfsqltype="CF_SQL_LONGVARCHAR">

, <cfqueryparam value="#form.Image_ID#" cfsqltype="cf_sql_integer">

, <cfqueryparam value="#now()#" cfsqltype="cf_sql_timestamp">

)
</cfquery>

</cfif>


<img id="theImage" class="hide">
<div id="theDescription" class="hide">
</div>

</body>
</html>

enter image description here

最佳答案

在没有所有细节的情况下,这里有一些基本的 jQuery 来设置 HTML 表单输入的值(这就是您想要的“论坛变量”吗?)。

car someImageId = 123;

// Assumes you have a button with id="myButton" to trigger this event.
$("#myButton").click(function(){

// Set it to a literal string
$("#Image_ID").val("value goes here");

// Or you could set it to a variable (perhaps this variable is initialized/set when the page loads w/ data from the server)
$("#Image_ID").val(someImageId);

});

关于jquery - JQuery 和论坛,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21414663/

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