Is there a way to set the page title by data-binding using Knockout.js?

前端 未结 5 1062
春和景丽
春和景丽 2020-12-11 00:05

I have a viewModel with a Title property. I\'d like to set the page title using that property. Here\'s what I tried already, which didn\'t work:



        
5条回答
  •  粉色の甜心
    2020-12-11 00:53

    Try giving your html element an id

    
    

    and applying your viewModel to it

    ko.applyBindings(viewModel, document.getElementById("htmlTop"));
    

    EDIT

    This works for me; I just ran this page and the title said "Hello". Double check your code for typos.

    
    
        
          
    
          
          
    
          
    
        
    
        
        
    
    

    Screenshot:

    enter image description here

提交回复
热议问题