简体   繁体   English

如何从脚本获取数据并以php形式显示(对话框)?

[英]How to get data from script and display in php form (dialog box)?

I have a requirement where 我有一个要求

<div class="button" id="room_open" value="<?php echo $Records['room_id'];?>" onclick="tappedOnRoom(<?php echo $Records['room_id'].","."'".$Records['room_status']."'".","."'".$Records['block_num']."'";?>)"><?php echo $Records['block_num']."-".$Records['room_id'];?></div>

And my script is: 我的脚本是:

function tappedOnRoom(id,status,block){                     
if(status == 'Open')            
   {                
      $(function() {
         $( "#dialog" ).dialog({ title: "Book a Room",width: 835, height:300});
       });
    }
}

So, when my div is clicked, the script checks the status and if the status is " Open ", then a form opens in a dialog box. 因此,当单击我的div时,脚本将检查status ,如果status为“ 打开 ”,则会在对话框中打开一个窗体。 So, my requirement is that I need to display block_num and room_id in the form dynamically. 因此,我的要求是我需要动态显示block_numroom_id

My form contains: 我的表格包含:

<output type="text" id="blockNum" name="blockNum" class="span6" value=""/>
<output type="text" id="roomNum" name="roomNum" class="span6" value=""/>

Now, I would like to display block and status in the above output types. 现在,我想在上述输出类型中显示blockstatus

Looks like you're passing it to a function. 看起来您正在将其传递给函数。 So this would be fairly easy using JQuery. 因此,使用JQuery会很容易。

In your tappedOnRoom function: 在您的tappedOnRoom函数中:

$(function() {
    $( "#dialog" ).dialog({ title: "Book a Room",width: 835, height:300});
    $("#blockNum").val(block);
    $("#roomNum").val(status);
}

You may also want to look at this example for a different way to write it. 您可能还想看看此示例 ,以另一种方式编写它。

Edit 编辑

I would advise you to not use the output tag. 我建议您不要使用输出标签。 To be honest it is not a tag I have used and the examples I have seen, make it seem like they are really designed for simple calculations. 老实说,它不是我使用过的标签,也不是我看到的示例,因此它们似乎确实是为简单计算而设计的。 Furthermore they are not supported by Internet Explorer. 此外,Internet Explorer不支持它们。 While most people don't use IE anymore, and developers tend to have a wide variety of angry epithets at the ready when the browser is mentioned, the fact is that you are still making your application unusable for a large number of people. 虽然大多数人不再使用IE,并且当提到浏览器时,开发人员往往会准备好各种各样的愤怒词,但事实是您仍在使应用程序对许多人不可用。

SO, instead I would advise you to use a <span> or <div> tag which works on all browsers, and which Jquery can insert into quite easily, Simply replace your output tags with something like this: 因此,相反,我建议您使用在所有浏览器上都可以使用的<span><div>标记,并且可以将Jquery轻松插入其中,只需将输出标记替换为以下内容:

<div id="blockNum" name="blockNum" class="span6"> </div>
<div id="roomNum" name="roomNum" class="span6"> </div>

Then you can adapt the JQuery to something like this: 然后,您可以将JQuery修改为以下形式:

$(function() {
    $( "#dialog" ).dialog({ title: "Book a Room",width: 835, height:300});
    $("#blockNum").text(block);
    $("#roomNum").text(status);
}

Regarding your hiding of divs, this is primarily a CSS question, although you can use JQuery to actually program the CSS. 关于div的隐藏,这主要是一个CSS问题,尽管您可以使用JQuery对CSS进行实际编程。 It wasn't clear to me that you didn't actually have the dialog portion down as far as hiding. 对我来说不清楚,您实际上并没有将对话部分降低到隐藏的程度。 I did a quick search and found this which looks like it does exactly what you want - just substitute the JQuery #opener for #room_open . 我做了快速搜索,发现这个看起来像它正是你想要的-刚刚替补JQuery的#opener#room_open It makes use of the show feature of .dialog . 它利用.dialogshow功能。

PS in this example they use special effects. PS在此示例中使用特殊效果。 I believe you can use "appear" and "hide", and you can certainly just shorten the duration, to avoid any animations, if you wanted to. 我相信您可以使用“出现”和“隐藏”,并且当然可以缩短播放时间,以免出现任何动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM