我不确定这是否可行,但是可以切换字符串吗?我有一个字符串,用于回显数据库。我希望切换刺痛,因为字符串读出的所有产品都是巨大的,以使页面更加用户友好。
mysqli_report(MYSQLI_REPORT_INDEX); //overrid a common php nonsense error
$fc_sel = $dbc->query("SELECT * FROM Food_Cat");
$fc_sel->data_seek(0);
echo("<br>");
echo("<button onclick='toggle_visibility('forms')'>Hello!</button>");
echo("<div class='forms'>");
while ($output = $fc_sel->fetch_assoc()) {
$fc_run .= $output['Food_Cat_name'] . $output['Food_Cat_Desc'] . '<br>';
$_SESSION['Food_Cat_name'] = $output['Food_Cat_name']; //echo out product name
$_SESSION['Food_Cat_Desc'] = $output['Food_Cat_Desc']; //echo out product desc
// echo out all add on's and delete button
echo("<div id='header'>");
echo(" <p id='session'>" . $_SESSION['Food_Cat_name'] . " </p>");
echo("</br>");
echo("<input type='button' id='submit_addon' name='submit_addon' onclick='toggle_visibility('forms')'>");
echo("</div>");
的Javascript
//turn entire div into toggle
function toggle_visibility(id) {
var e = document.getElementById(id);
if (e.style.display == 'block' || e.style.display == '')
e.style.display = 'none';
else
e.style.display = 'block';
}
我已经测试了我在HTML上使用的内容,它的工作原理非常完美。但是在字符串中不起作用。 任何建议。
答案 0 :(得分:2)
使用\'
echo('<input type="button" id="submit_addon" name="submit_addon" onclick="toggle_visibility(\'forms\')">');
在您的javascript中使用http://api.jquery.com/toggle/
function toggle_visibility(id) {
$( "#"+id ).toggle();
}
答案 1 :(得分:1)
extension UIFont {
func smallCapsFontVariant(smallCapsForUppercase: Bool = true) -> UIFont {
var features = [
[UIFontFeatureTypeIdentifierKey: kLowerCaseType,
UIFontFeatureSelectorIdentifierKey: kLowerCaseSmallCapsSelector]
]
if smallCapsForUppercase {
features.append([UIFontFeatureTypeIdentifierKey: kUpperCaseType,
UIFontFeatureSelectorIdentifierKey: kUpperCaseSmallCapsSelector])
}
let smallCapsFontDescriptor = fontDescriptor().fontDescriptorByAddingAttributes([
UIFontDescriptorFeatureSettingsAttribute : features
])
return UIFont(descriptor: smallCapsFontDescriptor, size: 0d)
}
此Javascript函数将检查HTML元素的“ID”标记。在您的视图代码中,您有“表单”,但它是类,不是ID 。
要使其正常工作,请在视图文件中更改DIV元素:
function toggle_visibility(id) {
var e = document.getElementById(id);
if (e.style.display == 'block' || e.style.display == '')
e.style.display = 'none';
else
e.style.display = 'block';
}
而不是
<div id='forms'>