我正在尝试插入html,具体取决于用户是否选择了Facebook页面。截至目前我的主要功能(searchOrDropdown())无效。我正在尝试进行故障排除,我想确保以正确的方式使用inner.HTML js方法。
谢谢!
var getDropDown = function () {
return '
<div class="btn-group page-actions" dropdown is-open="status.isopen" id ="dropdown_html">
<button id="button_current_page_name" type="button" class="btn background-color-transparent color-text dropdown-toggle" data-toggle="dropdown">
<span class="hidden-sm hidden-xs" id="user_pages_selected">Loading your Facebook pages...</span> <i class="fa fa-angle-down"></i>
</button>
<ul id="ul_user_pages_list" class="dropdown-menu" role="menu">
</ul>
</div>';
};
var getSearchBar = function () {
return '
<div class="search-wrapper">
<form>
<input style="border-radius:15px" onkeyup ="PagesDropDown.pageValueDidChange(value)" style= "margin-top: 0.5cm" type="text" value="" required class="search-box" placeholder= "Enter your page" autofocus>
</form>
</div>';
};
var searchOrDropdown=function(value)
{
//TODO find the wrapper element
var wrapper = document.getElementById("sdparent_wrapper"));
if (!FacebookPage.currentPage) {
wrapper.innerHTML = getSearchBar();
} else{
wrapper.innerHTML = getDropDown();
}
};
答案 0 :(得分:1)
问题在于您的换行符。尝试在每行的末尾添加反斜杠:
var getDropDown = function () {
return '\
<div class="btn-group page-actions" dropdown is-open="status.isopen" id ="dropdown_html">\
<button id="button_current_page_name" type="button" class="btn background-color-transparent color-text dropdown-toggle" data-toggle="dropdown">\
<span class="hidden-sm hidden-xs" id="user_pages_selected">Loading your Facebook pages...</span> <i class="fa fa-angle-down"></i>\
</button>\
<ul id="ul_user_pages_list" class="dropdown-menu" role="menu">\
</ul>\
</div>';
};
您的代码中有一个太多的括号,因此也请更改以下内容:
var wrapper = document.getElementById("sdparent_wrapper");
答案 1 :(得分:0)
变化 var wrapper = document.getElementById(&#34; sdparent_wrapper&#34;)); to var wrapper = document.getElementById(&#34; sdparent_wrapper&#34;)