J查询和论坛 [英] J Query and Forum

查看:202
本文介绍了J查询和论坛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用JQuery如何使用

Using JQuery how would use

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

填写论坛变量。

一个按钮,如果用户点击它将确定注释将去哪里。这是我可以使用Image_ID链接每个注释到一个单独的图像。我想让它,使用户不必输入一个Image_ID数字

I want to have a button that if the user clicks it will determine where the comment will go. This is so I can link each comment to a separate image using an Image_ID. I want to make it so that the user does not have to enter a Image_ID number as is currently needed in the below forum.

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

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

The above is the part entered by hand that I need to get automated.

        <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> 

推荐答案

没有所有的细节,这里是一些基本的jQuery设置值一个HTML表单输入(这是你想要的论坛变量?)。

Without having all the details, here is some basic jQuery to set the value of an HTML form input (is this what you intended by "forum variable"?).

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);     

});

这篇关于J查询和论坛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆