如何从我的Javascript中删除null
下面是我的脚本:如何从我的Javascript中删除null,javascript,html,select,Javascript,Html,Select,下面是我的脚本: $(function () { // define this here because we're changing the ID var $twitter = $('twitter'); // bind to select inside iframe $('#iframe').on('load', function () { $(this).contents().find('#cds').change(function () {
$(function () {
// define this here because we're changing the ID
var $twitter = $('twitter');
// bind to select inside iframe
$('#iframe').on('load', function () {
$(this).contents().find('#cds').change(function () {
var selectVal = $(this).val();
url = 'https://twitter.com/intent/tweet?button_hashtag=stream&text=Just enjoying ' + selectVal + ' on';
$twitter.attr("id", url);
}).change(); // trigger change to get initial value
});
});
基本上,它从我的选择框中获取所选值,并将其输出到twitter链接中。问题是,当未选择任何内容时,它会输出“null”,我想知道是否有办法检测到这一点,并回显其他内容。尝试以下方法:
var selectVal = $(this).val() || 'default value';
$(this.val()| |“其他东西”
如果答案有效,你能接受吗?那太好了谢谢