你好,我是 javascript 新手,我只是想问一下是否可以在函数中获取值?
示例代码
function a(){
var sample = "hello world"
};
Run Code Online (Sandbox Code Playgroud)
然后我将转到全局上下文并获取变量 sample
sample2 = sample
console.log(sample2);
Run Code Online (Sandbox Code Playgroud)
当我 console.log sample2 然后 sample2 的值应该是“hello world”请分享您的知识我想在 javascript 中了解更多提前谢谢
我正在为我的应用程序搜索一个搜索框,我有两个字段firstname和lastname.我为它们创建了一个full_name方法.
档案型号:
def full_name
"#{self.firstname} #{self.lastname}"
end
Run Code Online (Sandbox Code Playgroud)
这是我的搜索方法
def self.search_by_full_name(search)
where("(fisrtname || lastname) LIKE :q", :q => "%#{search}%")
end
Run Code Online (Sandbox Code Playgroud)
Profile Controller:
def index
if params[:search]
@profile = Profile.search_by_full_name(params[:search])
else
@profile = Profile.all
end
Run Code Online (Sandbox Code Playgroud)
结束
我目前正在我选择的 js 中显示选定的值。
如您所见,我的选择框并未呈现所有单词。我想在新行上看到文本值
我已经尝试过这段代码,但似乎没有任何反应
有人可以告诉我我缺少什么吗?
div#doctrine_doctrinecontent_attributes_topic_id_chosen {
display: inline;
}
Run Code Online (Sandbox Code Playgroud)
$('.chosen-select').chosen({
allow_single_deselect: true,
no_results_text: 'No results matched',
width: '100%',
});
Run Code Online (Sandbox Code Playgroud)