我想基于MySql Value显示/隐藏元素
$(document).bind('DOMNodeInserted', '#composeHeaderTable0', function(event) {
if ($('#data_parent_type0').val() == 'Leads') {
$("#email_template0 option[value='151ddf5a-3fe8-84bd-50db-533545893c67']").hide();
$("#email_template0 option[value='15a6040b-bbad-1a89-d62b-537de2b73832']").show();
}
if ($('#data_parent_type0').val() == 'Contacts') {
$("#email_template0 option[value='1b560788-07b2-0798-6b09-5335520bd9df']").hide();
$("#email_template0 option[value='f15bf4b4-d174-f0d6-6f09-537c8d3e9693']").show();
}
return false;
});
上面的脚本有效,但我需要显示基于Mysql调用的hide: 我有部分php对应文件
<?php
mysql_connect('mysql', 'admin', '123');
mysql_select_db('mydb');
$Leads0emailAddress0 = mysql_real_escape_string($_POST['Leads0emailAddress0']);
$result = mysql_query('select id from email_templates where description = 'Customers' and deleted = 0;');
...............
?>
答案 0 :(得分:1)
使用隐藏的表单元素,将其值设置为从mysql获取的结果。为该表单元素分配特定ID。从jQuery,使用ID引用该表单元素。这应该可以解决问题。
答案 1 :(得分:0)
您的mysql脚本有错误
$result = mysql_query('select id from email_templates where description = 'Customers' and deleted = 0;');
将其更改为
$result = mysql_query(
"SELECT id FROM
email_templates
WHERE
description = 'Customers'
AND deleted = 0"
);
列出结果
$options = '';
while($row = mysql_fetch_assoc($result)) {
$options .= '<option value="'.$row['id'].'">'.$row['id'].'</option>' . "\n";
}
//display the options list in html where you want
<select id="email_template0">
<?php echo $options; ?>
</select>
现在来自下拉列表更改的jQuery句柄事件
$(function() {
$("#email_template0").change(function() {
alert( $('option:selected', this).val() );
//do your hide and select here
});
});