Javascript按钮onclick不起作用

时间:2016-12-15 11:17:36

标签: javascript onclick buttonclick

下面你们这些人是我代码中的两个片段:

            case 'i_new_call':
        {
            if (oSipSessionCall) {
                // do not accept the incoming call if we're already 'in call'
                e.newSession.hangup(); // comment this line for multi-line support
            }
            else {
                oSipSessionCall = e.newSession;
                oSipSessionCall.setConfiguration(oConfigCall);
                uiBtnReceive('Answer');
                btnCall.disabled = true;
                btnHangUp.disabled = false;

                startRingTone();

                var sRemoteNumber = (oSipSessionCall.getRemoteFriendlyName() || 'unknown');
                txtCallStatus.innerHTML = "<i>Incoming call from [<b>" + sRemoteNumber + "</b>]</i>";
                showNotifICall(sRemoteNumber);
            }
            break;
        }

我的功能是:

function uiBtnReceive() {

            var btnAccept = document.getElementsByName("Accept");
            btnAccept.onclick = function () { sipCall(bDisableVideo ? 'call-audio' : 'call-audiovideo'); };
        }
    }

按钮:

<input type="button" name="Accept" style="margin: 0; vertical-align:middle; height: 100%;" class="btn btn-primary" value="Accept"/>

问题是,当我创建id为btnAccept的按钮时,它可以工作。但是,当我尝试使用元素名称时,它不会触发。我知道如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

getElementsByName返回array elements index您需要使用object获取event并附加function uiBtnReceive() { var btnAccept = document.getElementsByName('Accept')[0]; btnAccept.onclick = function () { sipCall(bDisableVideo ? 'call-audio' : 'call-audiovideo'); }; }

[Serializable]
public class ShortGuid : ISerializable
{
    public Guid Guid { get; }
    protected ShortGuid(SerializationInfo info, StreamingContext context)
    {
        Guid = Decode(info.GetString("Guid"));
    }

    public void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        info.AddValue("Guid", Encode(Guid));
    }
}