将 javascript 函数解析为两个不同的按钮 onclick
parsing javascript function to two different button onclick
大家好,我将下面的函数分成了两个单独的函数。这些功能不起作用,但我没有收到任何错误消息?
主要功能:
function sipToggleMute() {
if (oSipSessionCall) {
var i_ret;
var bMute = !oSipSessionCall.bMute;
txtCallStatus.innerHTML = bMute ? '<i>Mute the call...</i>' : '<i>Unmute the call...</i>';
i_ret = oSipSessionCall.mute('audio'/*could be 'video'*/, bMute);
if (i_ret != 0) {
txtCallStatus.innerHTML = '<i>Mute / Unmute failed</i>';
return;
}
oSipSessionCall.bMute = bMute;
btnMute.value = bMute ? "Unmute" : "Mute";
}
}
解析函数:
function sipMute() {
if (oSipSessionCall) {
var i_ret;
var bMute = !oSipSessionCall.bMute;
txtCallStatus.innerHTML = '<i>Mute the call...</i>';
i_ret = oSipSessionCall.mute('audio'/*could be 'video'*/, bMute);
if (i_ret != 0) {
txtCallStatus.innerHTML = '<i>Mute failed</i>';
return;
}
oSipSessionCall.bMute = "Unmute";
}
}
function sipunMute() {
if (oSipSessionCall) {
var i_ret;
var bMute = !oSipSessionCall.bMute;
txtCallStatus.innerHTML = '<i>Unmute the call...</i>';
i_ret = oSipSessionCall.mute('audio', bMute);
if (i_ret != 0) {
txtCallStatus.innerHTML = '<i> Unmute failed</i>';
return;
}
oSipSessionCall.bMute = "Mute";
}
您的两个函数都在切换当前状态,原因是:
var bMute = !oSipSessionCall.bMute;
一个函数应设置为true
,另一个应设置为false
function sipMute() {
if (oSipSessionCall) {
var i_ret;
var bMute = true;
txtCallStatus.innerHTML = '<i>Mute the call...</i>';
i_ret = oSipSessionCall.mute('audio'/*could be 'video'*/, bMute);
if (i_ret != 0) {
txtCallStatus.innerHTML = '<i>Mute failed</i>';
return;
}
oSipSessionCall.bMute = bMute;
// btnMute.value = "Unmute";
}
.
function sipunMute() {
if (oSipSessionCall) {
var i_ret;
var bMute = false;
txtCallStatus.innerHTML = '<i>Unmute the call...</i>'
i_ret = oSipSessionCall.mute('audio', bMute);
if (i_ret != 0) {
txtCallStatus.innerHTML = '<i> Unmute failed</i>';
return;
}
oSipSessionCall.bMute = bMute;
//btnMute.value = "Mute";
}
如果您有两个不同的按钮,比如 btnMute
和 btnUnmute
,那么您不需要 btnMute.value...
。
假设您的 oSipSessionCall.bMute
属性:
的初始状态为 false(未静音)
var oSipSessionCall = {
bMute: false
}
您可以使用一个切换功能来使您的播放器静音和取消静音(我假设您使用的是 jQuery 并且您的按钮的名称为 属性 toggle
) :
$('[name=toggle]').on('click', function() {
var i_ret;
if (oSipSessionCall) {
txtCallStatus.innerHTML = oSipSessionCall.bMute ? '<i>Mute the call...</i>' : '<i>Unmute the call...</i>';
i_ret = oSipSessionCall.mute('audio'/*could be 'video'*/, oSipSessionCall.bMute);
if (i_ret !== 0) {
txtCallStatus.innerHTML = '<i>Mute failed</i>';
return;
}
oSipSessionCall.bMute = !oSipSessionCall.bMute;
}
});
大家好,我将下面的函数分成了两个单独的函数。这些功能不起作用,但我没有收到任何错误消息? 主要功能:
function sipToggleMute() {
if (oSipSessionCall) {
var i_ret;
var bMute = !oSipSessionCall.bMute;
txtCallStatus.innerHTML = bMute ? '<i>Mute the call...</i>' : '<i>Unmute the call...</i>';
i_ret = oSipSessionCall.mute('audio'/*could be 'video'*/, bMute);
if (i_ret != 0) {
txtCallStatus.innerHTML = '<i>Mute / Unmute failed</i>';
return;
}
oSipSessionCall.bMute = bMute;
btnMute.value = bMute ? "Unmute" : "Mute";
}
}
解析函数:
function sipMute() {
if (oSipSessionCall) {
var i_ret;
var bMute = !oSipSessionCall.bMute;
txtCallStatus.innerHTML = '<i>Mute the call...</i>';
i_ret = oSipSessionCall.mute('audio'/*could be 'video'*/, bMute);
if (i_ret != 0) {
txtCallStatus.innerHTML = '<i>Mute failed</i>';
return;
}
oSipSessionCall.bMute = "Unmute";
}
}
function sipunMute() {
if (oSipSessionCall) {
var i_ret;
var bMute = !oSipSessionCall.bMute;
txtCallStatus.innerHTML = '<i>Unmute the call...</i>';
i_ret = oSipSessionCall.mute('audio', bMute);
if (i_ret != 0) {
txtCallStatus.innerHTML = '<i> Unmute failed</i>';
return;
}
oSipSessionCall.bMute = "Mute";
}
您的两个函数都在切换当前状态,原因是:
var bMute = !oSipSessionCall.bMute;
一个函数应设置为true
,另一个应设置为false
function sipMute() {
if (oSipSessionCall) {
var i_ret;
var bMute = true;
txtCallStatus.innerHTML = '<i>Mute the call...</i>';
i_ret = oSipSessionCall.mute('audio'/*could be 'video'*/, bMute);
if (i_ret != 0) {
txtCallStatus.innerHTML = '<i>Mute failed</i>';
return;
}
oSipSessionCall.bMute = bMute;
// btnMute.value = "Unmute";
}
.
function sipunMute() {
if (oSipSessionCall) {
var i_ret;
var bMute = false;
txtCallStatus.innerHTML = '<i>Unmute the call...</i>'
i_ret = oSipSessionCall.mute('audio', bMute);
if (i_ret != 0) {
txtCallStatus.innerHTML = '<i> Unmute failed</i>';
return;
}
oSipSessionCall.bMute = bMute;
//btnMute.value = "Mute";
}
如果您有两个不同的按钮,比如 btnMute
和 btnUnmute
,那么您不需要 btnMute.value...
。
假设您的 oSipSessionCall.bMute
属性:
var oSipSessionCall = {
bMute: false
}
您可以使用一个切换功能来使您的播放器静音和取消静音(我假设您使用的是 jQuery 并且您的按钮的名称为 属性 toggle
) :
$('[name=toggle]').on('click', function() {
var i_ret;
if (oSipSessionCall) {
txtCallStatus.innerHTML = oSipSessionCall.bMute ? '<i>Mute the call...</i>' : '<i>Unmute the call...</i>';
i_ret = oSipSessionCall.mute('audio'/*could be 'video'*/, oSipSessionCall.bMute);
if (i_ret !== 0) {
txtCallStatus.innerHTML = '<i>Mute failed</i>';
return;
}
oSipSessionCall.bMute = !oSipSessionCall.bMute;
}
});