问题
I'm having a focus issue with Silverlight...
How can I set the focus to my Silverlight control using javascript?
回答1:
Add the following to your Silverlight hosting page (just above the onSilverlightError function):
function appLoad(sender, args) {
var xamlObject = document.getElementById('SilverlightObject');
if (xamlObject != null)
xamlObject.focus();
}
In the object declaration itself (e.g. in <object id='SilverlightObject'
) add this after <param name="onError" value="onSilverlightError" />
:
<param name="onLoad" value="appLoad" />
Also make sure the object names match (in this case 'SilverlightObject')
来源:https://stackoverflow.com/questions/4107460/set-focus-to-a-silverlight-control-from-javascript