我怎样才能显示一个按钮,点击一个div的价值? [英] How can I display value of a div with a button click?
问题描述
我目前正在与大规模杀伤性武器的编辑和jQuery UI的标签。我已经创建了一个AJAX / JS的功能,将提交(点击下一步按钮时)的 wmd- preVIEW
值,然后PHP呼应的结果选项卡2。问题是,我没有收到任何显示结果。我不是在寻找文本区域
的价值,但在div #wmd- preVIEW
值。我怎样才能通过我的Ajax /功能显示的div wmd- preVIEW
的价值呢?
JS
<脚本>
$(函数(){
变量$标签= $('#标签)。标签({
禁用:[0,1]
选择:函数(){
$阿贾克斯({
键入:POST,
网址:post_tabs.php
数据: {
大规模杀伤性武器:$ VAL(#wmd- preVIEW)()。
},
成功:函数(结果){
$(#标签-2)HTML(结果);
}
});
}
});
$(UI-标签面板)。每个(函数(一){
VAR totalSize = $大小() - 1(UI-标签面板。)。
如果(我!= totalSize){
接下来= I + 2;
$(本).append(< A HREF =#类='下一个标签发相对='+接下来+'>接下来页面和放大器;#187;< / A>中);
}
如果(ⅰ!= 0){
preV =我;
$(本).append(< A HREF =#类='preV-标签先行者相对='+ preV +'>&安培;#171; preV页及所述; / A>中);
}
});
$('。下一选项卡)。点击(函数(){
VAR currentTab = $('#标签)选项卡(选择''选项')。
如果 (
(
currentTab == 0安培;&安培; / *(B)* /
。$ .trim($('#大规模杀伤性武器输入)VAL())长度GT; 0
)
){
VAR的tabIndex = $(本).attr(相对);
$ tabs.tabs(启用,的tabIndex).tabs(选择,的tabIndex).tabs(选项,残障人士,[0,1]);
} 其他 {
开关(currentTab){
情况下0:
警报(请填写所有必填字段。','警告对话框');
打破;
}
}
的console.log(preventing默认);
返回false;
});
$('。preV-选项卡)。点击(函数(){
VAR的tabIndex = $(本).attr(相对);
$ tabs.tabs(启用,的tabIndex).tabs(选择,的tabIndex).tabs(选项,残障人士,[0,1]);
返回false;
});
});
< / SCRIPT>
PHP
&LT ;?
如果(使用isset($ _ POST ['大规模杀伤性武器'])){
$ WMD = $ _ POST ['大规模杀伤性武器'];
回声(< DIV ID =text_result><跨度类=resultval>< H2>多行文本回声结果:其中; / H>'。$大规模杀伤性武器'< / SPAN>< / DIV>');
}
?>
HTML
< DIV ID =标签-1级=UI-标签面板UI的标签隐藏>
< DIV ID =大规模杀伤性武器按钮栏>< / DIV>
< textarea的ID =大规模杀伤性武器输入NAME =大规模杀伤性武器输入COLS =92行=15的tabindex =6>< / textarea的>
< DIV ID =wmd- preVIEW>< / DIV>
< / DIV>
< DIV ID =标签-2级=UI-标签面板UI的标签隐藏>
< / DIV>
PHP code应该从< PHP
,你开始与<
这是不正确。
当你看到psented文字PHP code $ P $ - 它应该告诉你,它没有运行,这就是为什么你一直得到输出像');$大规模杀伤性武器。 ?}>
,而不是真正的PHP回声输出。
其他意见仍然有效,以及 - 你不应该使用 $(#wmd- preVIEW)HTML()
或 $(#大规模杀伤性武器输入)。VAL()
,但你不能使用 VAL
上的div,这是行不通的。
在这种情况下 $(#大规模杀伤性武器输入)。VAL()
是更好的选择,只是因为这是什么原因输入
领域存在的 - 让输入。
让我知道,如果有更多的问题,我可以帮助。
I am currently working with a wmd editor and jQuery-UI tabs. I have created an ajax/js function that will submit (when next button is clicked) the wmd-preview
value and then php echo the result in tab 2. The problem is that I am not getting any results displayed. I am not looking for the textarea
value but the div #wmd-preview
value. How can I display the value of the div wmd-preview
through my ajax/function?
JS
<script>
$(function () {
var $tabs = $('#tabs').tabs({
disabled: [0, 1],
select: function () {
$.ajax({
type: "POST",
url: "post_tabs.php",
data: {
"wmd": $("#wmd-preview").val(),
},
success: function (result) {
$("#tab-2").html(result);
}
});
}
});
$(".ui-tabs-panel").each(function (i) {
var totalSize = $(".ui-tabs-panel").size() - 1;
if (i != totalSize) {
next = i + 2;
$(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page »</a>");
}
if (i != 0) {
prev = i;
$(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>« Prev Page</a>");
}
});
$('.next-tab').click(function () {
var currentTab = $('#tabs').tabs('option', 'selected');
if (
(
currentTab == 0 && /*(B)*/
$.trim($('#wmd-input').val()).length > 0
)
) {
var tabIndex = $(this).attr("rel");
$tabs.tabs('enable', tabIndex).tabs('select', tabIndex).tabs("option", "disabled", [0, 1]);
} else {
switch (currentTab) {
case 0:
alert('Please fill out all the required fields.', 'Alert Dialog');
break;
}
}
console.log("preventing default");
return false;
});
$('.prev-tab').click(function () {
var tabIndex = $(this).attr("rel");
$tabs.tabs('enable', tabIndex).tabs('select', tabIndex).tabs("option", "disabled", [0, 1]);
return false;
});
});
</script>
PHP
<?
if (isset($_POST['wmd'])){
$wmd = $_POST['wmd'];
echo ('<div id="text_result"><span class="resultval"><h2>Textarea Echo result:</h2>'.$wmd.'</span></div>');
}
?>
HTML
<div id="tab-1" class="ui-tabs-panel ui-tabs-hide">
<div id="wmd-button-bar"></div>
<textarea id="wmd-input" name="wmd-input" cols="92" rows="15" tabindex="6"></textarea>
<div id="wmd-preview"></div>
</div>
<div id="tab-2" class="ui-tabs-panel ui-tabs-hide">
</div>
PHP code should start with <?php
, yours start with <?
which is incorrect.
When you see PHP code presented as text - it should tell you it is not running, this is why you keep getting output like '.$wmd.''); } ?>
instead of real PHP echo output.
The other comment still stands as well - you should either use $("#wmd-preview").html()
or $("#wmd-input").val()
but you cannot use val
on divs, it does not work.
In this scenario $("#wmd-input").val()
is the better choice just because this is the reason input
fields exist - to get input.
Let me know if there are more questions I can help with.
这篇关于我怎样才能显示一个按钮,点击一个div的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!