IHTMLElement :: getAttribute()无法检索“占位符”输入元素? [英] IHTMLElement::getAttribute() can not retrieve "placeholder" of a input element?

查看:374
本文介绍了IHTMLElement :: getAttribute()无法检索“占位符”输入元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这样的输入编辑框

<input id="name" name="name" placeholder="Input Name ...">

我希望使用IHTMLElement :: getAttribute获取占位符属性文本,但它总是返回空字符串。

I wish to got placeholder attribute text using IHTMLElement::getAttribute, but it always returns empty string.

以下是我的代码

	std::wstring GetElementAttr(IHTMLElement* pElement, const std::wstring& szAttrName)
	{
        	if (!pElement) return L"";

		VARIANT szAttrValue;
		VariantInit(&szAttrValue);
		std::wstring szRet = L"";
		HRESULT hr = S_OK;

		hr = pElement->getAttribute(CComBSTR(szAttrName.size(), szAttrName.data()), 0, &szAttrValue);
		if (FAILED(hr)){
			VariantClear(&szAttrValue);
			return szRet;
		}
	
		if (szAttrValue.vt == VT_BSTR && szAttrValue.bstrVal){
			szRet = szAttrValue.bstrVal;
		}else if(szAttrValue.vt == VT_I4 ){
			szRet = string_utility::Int2String(szAttrValue.lVal);
		}
		
		VariantClear(&szAttrValue);
		return szRet;
	}

我尝试了第二种方式来使用IHTMLElement :: get_outerHTML,但它返回如下,占位符attr缺失

I tried second way to use IHTMLElement::get_outerHTML, but it returns as following with placeholder attr missing

<input id="name" name="name" placeholder="">

那么还有其他方法可以检索此HTML5属性吗?

So is there some other way to retrieve this HTML5 attribute?

推荐答案

您是否尝试过 IHTMLElement6 IHTMLElement5
IHTMLElement4 的成员?

Have you tried the members of IHTMLElement6, IHTMLElement5 or IHTMLElement4?

浏览器窗口是否真正识别占位符?也许它目前处于IE7模式。

Is placeholder actually recognized by your browser window? Maybe it is currently in IE7 mode.


这篇关于IHTMLElement :: getAttribute()无法检索“占位符”输入元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆